package com.hq.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.bean.Goods;
import com.hq.service.GoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @RequestMapping("list.do")
    public String list(Model model, @RequestParam(value = "cpage",defaultValue = "1")Integer cpage){
        Map map = new HashMap();
        PageHelper.startPage(cpage,3);
        List list = goodsService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }
    @RequestMapping("add.do")
    @ResponseBody
    public Object addGoods(Goods goods){
        int i = goodsService.addGoods(goods);
        return i;
    }
    @RequestMapping("toadd.do")
    public String toadd(){
        return "add";
    }
    @RequestMapping("del.do")
    @ResponseBody
    public Object del(Integer sid){
        int i = goodsService.delGoods(sid);
        return i;
    }
    @RequestMapping("brandlist.do")
    @ResponseBody
    public Object brandlist(){
        List list = goodsService.brandlist();
        return list;
    }
}
